package com.example.administrator.printoutindemo.http;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 小星 QQ:753940262
 * @class describe
 * @time 2019/9/10 0010 14:35
 */
public class Node {

    //请求参数拼接
    public static String getRequestParams(String namespace, Map<String, String> map) {
        if (map == null) {
            map = new HashMap<>();
        }
        StringBuffer sbf = new StringBuffer();
        sbf.append(Node.toStart("Request"));
        for (Map.Entry<String, String> entry : map.entrySet()) {
            sbf.append(Node.toStart(entry.getKey()));
            sbf.append(entry.getValue());
            sbf.append(Node.toEnd(entry.getKey()));
        }
        sbf.append(Node.toEnd("Request"));
//        String str = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
//                "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
//                "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
//                "  <soap:Header>\n" +
//                "    <Identify xmlns=\"http://tempuri.org/\">\n" +
//                "      <UserName>" + BaseConstants.USERNAME + "</UserName>\n" +
//                "      <PassWord>" + BaseConstants.PASSWORD + "</PassWord>\n" +
//                "    </Identify>\n" +
//                "  </soap:Header>\n" +
//                "  <soap:Body>\n" +
//                "    <" + namespace + " xmlns=\"http://tempuri.org/\">\n" +
//                "      <str>" + sbf.toString() + "</str>\n" +
//                "    </" + namespace + ">\n" +
//                "  </soap:Body>\n" +
//                "</soap:Envelope>";
//        String str =
//                "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
//                        "   <s:Header>\n" +
//                        "       <h:MySoapHeader xmlns:h=\"http://dyjapp.org/\" xmlns=\"http://dyjapp.org/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" +
//                        "           <UserName>xxlym</UserName>\n" +
//                        "           <PassWord>20190909</PassWord>\n" +
//                        "           <key1>1568084750741</key1>\n" +
//                        "           <key2>15A87793D78B72AF7001F20E7BFBAB00</key2>\n" +
//                        "       </h:MySoapHeader>\n" +
//                        "   </s:Header>\n" +
//                        "   <s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><LiKuNewTaskAutoStore xmlns=\"http://dyjapp.org/\"/>\n" +
//                        "   </s:Body>\n" +
//                        "</s:Envelope>\n";
        String str = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Header><h:MySoapHeader xmlns:h=\"http://dyjapp.org/\" xmlns=\"http://dyjapp.org/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><UserName>xxlym</UserName><PassWord>20190909</PassWord><key1>1568084750741</key1><key2>15A87793D78B72AF7001F20E7BFBAB00</key2></h:MySoapHeader></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><LiKuNewTaskAutoStore xmlns=\"http://dyjapp.org/\"/></s:Body></s:Envelope>";
        return str;
    }

    //"<"节点转义
    private static String toStart(String name) {
        return "<" + name + ">";
    }

    //">"节点转义
    private static String toEnd(String name) {
        return "</" + name + ">";
    }
}
